﻿using K8.CBB;
using System;
using System.Reflection;

namespace KingerRobot.XXX;
class StartHelper
{
    #region 单例模式
    //private static readonly object lockobject = new object();
    public static StartHelper Instance { get { return Singleton.Create<StartHelper>(); } }
    /// <summary>
    /// 构造函数
    /// </summary>
    private StartHelper()
    {
    }
    #endregion
    public int Start(Action<string> msg)
    {
        var result = InitializeService(msg);
        return result;
    }
    private int InitializeService(Action<string> msg)
    {
        var typeName = "KingerRobot.WLWebService.StartHelper,KingerRobot.WLWebService";
        var type = typeName.ToType();
        if (type == null)
        {
            return 0;
        }
        msg($"启动服务[{typeName}]……");
        var instance = type.GetProperty("Instance").GetValue(null);
        var method = instance.GetType().GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
        var result =  method.Invoke(instance, new object[] { msg });
        if (result == null)
        {
            return 0;
        }
        return result.ToString().ToInt(0);
    }
}
